package com.example.dell.fastshopping;

import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dell.fastshopping.MainActivity;
import com.example.dell.fastshopping.R;
import com.example.dell.fastshopping.loginRegist.LoginActivity;
import com.example.dell.fastshopping.loginRegist.RegistActivity;
import com.example.dell.fastshopping.utils.SPUtils;

import java.io.File;


/**
 * Created by i7-1 on 2018/12/6.
 */

public class SplashActivity extends AppCompatActivity {

    private ImageView mImgStart;
    private TextView countdown;
    int time = 5;
    private boolean should2MainAct = true;
    private Runnable runnable;

    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_splash);
        runnable = new Runnable() {
            @Override
            public void run() {
                time--;
                countdown.setText("跳过" + time + "s");
                if (time == 0 && should2MainAct) {
                    startActivity();
                } else if (time != 0) {
                    mImgStart.postDelayed(runnable, 1000);
                }

            }
        };
        initView();
    }

    private void initView() {
        mImgStart = (ImageView) findViewById(R.id.id_img_start);
        countdown = (TextView) findViewById(R.id.countdown);
        countdown.setText("跳过5s");
        mImgStart.postDelayed(runnable, 1000);
        findViewById(R.id.regist).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                should2MainAct = false;
                Intent intent = new Intent(SplashActivity.this, RegistActivity.class);
                startActivity(intent);
                finish();
            }
        });

        findViewById(R.id.login).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                should2MainAct = false;
                Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }

    private void startActivity() {

        Intent intent = new Intent(SplashActivity.this, MainActivity.class);
        startActivity(intent);
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
        finish();
    }

}
